package com.poetize.plus.entity.vo.page;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.Label;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zuosy
 * @created 2024/4/16 15:53
 */
public record LabelPageVO(
        @Schema(description = "分类ID")
        Long sortId,
        @Schema(description = "id")
        Long labelId,
        @Schema(description = "标签名称")
        String labelName,
        @Schema(description = "标签描述")
        String labelDescription,
        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime createTime
) {
        /**
         * 实体类集合转分页集合
         * @param labelList
         * @return
         */
        public static List<LabelPageVO> convertPage(List<Label> labelList){
                List<LabelPageVO> result = new ArrayList<>();
                labelList.forEach(label -> {
                        LabelPageVO vo = new LabelPageVO(
                                label.getSortId(),
                                label.getLabelId(),
                                label.getLabelName(),
                                label.getLabelDescription(),
                                label.getCreateTime());
                        result.add(vo);
                });
                return result;
        }
}
